import React from 'react';
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as Action from "../actions";

class Confirm extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        var count=0;
        const keepTwoDecimal=(num)=>{
            var result = parseFloat(num);
            result = Math.round(num * 100) / 100;
            return result;
        }
        return <section className="queren">
            <div className="order">
                <div className="banner">
                    <h3>订单详情</h3>
                    <ul>
                        {
                            this.props.shop.map((item,idx) => {
                                let priceC = 0;
                                priceC = item.quantity * item.price;
                                count += priceC;
                                return <li key={idx}>
                                    <div className="product">
                                        <img src={item.icon} />
                                        <h4>{item.name}</h4>
                                    </div>
                                    <div className="data">
                                        <span className="quantity">×{item.quantity}</span>
                                        <span className="price">￥{keepTwoDecimal(priceC)}</span>
                                    </div>
                                </li>

                            })
                        }
                        <li>
                            <h4 className="count">总计</h4>
                            <span className="countP">￥{keepTwoDecimal(count)}</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>
    }
}
export default connect(
    ({ foodReducer }) => {
        return {
            shop: foodReducer.shop
        }
    }
)(Confirm)